package com.example.demo.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public class LogService {
    //设置事务的传播机制
    //其实写下面的参数和不写的效果是一样的,因为本身默认就为下面的
    @Transactional(propagation = Propagation.REQUIRED)
//    @Transactional(isolation = )
    public int add(){
        try {
            int num = 100/0;
        } catch (Exception e) {
//            e.printStackTrace();
            //手动回滚异常
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return 1;
    }
}
